## 直接插入排序
def directInsertSort(nums):
    for i in range(1,len(nums)):
        temp = nums[i]
        j = i-1
        while j>=0 and temp<nums[j]:
            nums[j+1] = nums[j]
            j-=1
        nums[j+1] = temp
    return nums

def shellSort(nums):
    gap = len(nums)//2 # 初始间距

    # 逐步缩小间距
    while gap > 0:
        for i in range(gap,len(nums)):
            temp = nums[i]
            j = i
            # 将当前元素插入到适当的位置
            while j >= gap and nums[j-gap] > temp:
                nums[j] =nums[j-gap]
                j-=gap # 这块的作用是什么？若需要交换，通过j，先把前边大的交换到小的地方，然后将前边替换为temp也就是后边小的
            nums[j] = temp
        gap = gap//2  # 缩小间距
    return nums

def BubbleSort(nums):
    n = len(nums)
    # 从外层循环控制比较的轮数
    for i in range(n):
        # 从内层循环进行相邻元素比较
        for j in range(0,n-i-1):
            # 如果当前元素大于下一个元素，则交换
            if nums[j+1] < nums[j]:
                nums[j+1],nums[j] = nums[j],nums[j+1]
            
    return nums


def SimpleSwitchSort(nums):
    n = len(nums)
    # 外层循环控制每一轮选择
    for i in range(0,n):
        min_index = i  # 假设当前索引为最小值的索引
        # 内层循环查找剩余部分的最小值
        for j in range(i+1,n):
            if nums[j] < nums[min_index]:
                min_index = j 
        # 交换当前元素和找到的最小值
        nums[i],nums[min_index] = nums[min_index],nums[i]

    return nums

if __name__ == '__main__':
    nums = [1,3,5,7,9,2,4,6,8,0]
    print(SimpleSwitchSort(nums))


